package br.gov.capgov.treinamento.ejb.sessionbeans;

import java.util.List;

import javax.ejb.Stateless;
import javax.persistence.EntityManager;
import javax.persistence.NoResultException;
import javax.persistence.PersistenceContext;
import javax.persistence.Query;

import br.gov.capgov.treinamento.jpa.entidades.InfoUrl;
import br.gov.capgov.treinamento.jpa.entidades.Url;

@Stateless 
public class InfoUrlEJB
{
	@PersistenceContext
	private EntityManager manager;
	
	public List<InfoUrl> procurarInfomacoesUrl(Url url)
	{
		Query query = manager.createQuery("select u from "+ InfoUrl.class.getName() + " as u where url_id = "+ url.getId() +" ");
		
		try
		{ 
			List<InfoUrl> infoUrls = query.getResultList();		
			return infoUrls;
		}
		catch (NoResultException e)
		{
			return null;
		}		
	}
	
	public void insereInfoUrl(InfoUrl infoUrl)
	{
		manager.persist(infoUrl);	
	}
	
	public void removeInfoUrl(Integer id)
	{
		InfoUrl infoUrl = manager.find(InfoUrl.class, id);
		manager.remove(infoUrl);	
	}
}